1. /* sdmd2lng.cpp by K.Tsuru */
  2. // function ID = 316 DRADIX
  3. /*********************************************************
  4. SDouble class
  5. It tries to convert the value "SDouble d" into the form
  6. d = L * 10^e (long L), L < SlOpMaxValue().
  7. See "sdbl.h".
  8. *********************************************************/
  9. #ifndef SN_H
  10. #include "sn.h"
  11. #endif
  12. bool SDouble::ConvTolongExp(long* L, long* e) const {
  13. if(Sign(316) == 0){
  14. *L = *e = 0; return true;
  15. }
  16. if(Type() != REAL) SetError(RADIX_ERR, "ConvTolongExp", 316);
  17. int h = (int)Last(), t = (int)First(), f = h-t, j;
  18. if(f > 2) return false; // 0.0001 2345 6789 1000 (f=3) > SlOpMaxValue()
  19. double rdx = DRADIX, r = figure(h), mt = (double)SlOpMaxValue();
  20. #ifndef NDEBUG
  21. assert(h);
  22. #endif
  23. for(j = h-1; j >= t; j--){
  24. r += figure(j)*rdx;
  25. rdx *= DRADIX;
  26. }
  27. *e = long(RdxExp() - h)*(long)DFIGURES;
  28. if(r > mt){
  29. while( fmod(r, 10.0) < DBL_EPSILON){ //It removes lower zeros.
  30. (*e)++; r /= 10.0;
  31. // if( (r < mt) && !( abs(*e) % DFIGURES) ) break; Do not reach here.
  32. }
  33. }
  34. r += ROUND_DBL_INT; //Maybe it is not necessary.
  35. if(r > mt) return false;
  36. // convert to long
  37. if(Sign(316) > 0) *L = (long)r;
  38. else *L = -(long)r;
  39. return true;
  40. }

sdmd2lng.cpp : last modifiled at 2015/11/25 20:14:48(1,245 bytes)
created at 2017/10/07 10:21:15
The creation time of this html file is 2017/10/07 10:30:03 (Sat Oct 07 10:30:03 2017).